package com.jianglin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianglin.mapper.OwnerMapper;
import com.jianglin.model.Owner;
import com.jianglin.service.IOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OwnerServiceImpl  implements IOwnerService {

    @Autowired
    private OwnerMapper ownerMapper;

    @Override
    public PageInfo<Owner> findOwnerAll(int page, int pagesize, Owner owner) {
        PageHelper.startPage(page, pagesize);
        List<Owner> list = ownerMapper.queryOwnerAll(owner);
        return new PageInfo<>(list);
    }

    @Override
    public Owner queryOwnerByName(String username) {
        return ownerMapper.queryOwnerByName(username);
    }

    @Override
    public int add(Owner owner) {
        owner.setPassword("123456"); // 默认密码
        return ownerMapper.insertOwner(owner); // 调用修改后的方法
    }

    @Override
    public int delete(Long id) {
        return ownerMapper.deleteOwnerById(id);
    }

    @Override
    public int updateData(Owner owner) {
        return ownerMapper.updateOwner(owner);
    }

    @Override
    public Owner findById(Long id) {
        return ownerMapper.queryOwnerById(id);
    }

    @Override
    public void deleteOwnerUserByUserName(String username) {
        ownerMapper.deleteOwnerUserByUserName(username);
    }

    @Override
    public Owner queryOwnerById(long id) {
        return ownerMapper.queryOwnerById(id);
    }

    // 新增分页实现
    @Override
    public PageInfo<Owner> findListByPage(Integer page, Integer pageCount) {
        PageHelper.startPage(page, pageCount);
        List<Owner> list = ownerMapper.findAll();
        return new PageInfo<>(list);
    }
}
